package com.niji.littly_donkey_android.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.StrictMode;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.makeramen.roundedimageview.RoundedImageView;
import com.niji.littly_donkey_android.R;
import com.niji.littly_donkey_android.bean.CommentFabulous;
import com.niji.littly_donkey_android.util.BitMapUtil;
import com.niji.littly_donkey_android.util.CirclePhotoUtil;
import com.niji.littly_donkey_android.util.NetworkGlideImageLoader;
import com.niji.littly_donkey_android.view.CircleImageView;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

public class CommentFabulousAdapter extends ArrayAdapter<CommentFabulous> {


    private static final String TAG = "CommentFabulousAdapter";
    private Context context;

    public CommentFabulousAdapter(Context context, ArrayList<CommentFabulous> members)
    {
        super(context,0, members);
        this.context = context;
    }
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        CommentFabulous commentFabulous = getItem(position);

        if(convertView == null)
        {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_comment_fabulous, parent, false);
        }

        CircleImageView head = convertView.findViewById(R.id.comment_fabulous_head);
        RoundedImageView img = convertView.findViewById(R.id.comment_fabulous_img);
        TextView commentFabulousName = convertView.findViewById(R.id.comment_fabulous_name);
        TextView commentFabulousId = convertView.findViewById(R.id.comment_fabulous_id);
        TextView commentFabulousUserId = convertView.findViewById(R.id.comment_fabulous_userId);
        TextView commentFabulousCommentsId = convertView.findViewById(R.id.comment_fabulous_commentsId);
        TextView commentFabulousMessage = convertView.findViewById(R.id.comment_fabulous_message);
        TextView commentFabulousCf = convertView.findViewById(R.id.comment_fabulous_cf);
        TextView commentFabulousTime = convertView.findViewById(R.id.comment_fabulous_time);
        //thumb.setImageBitmap(BitMap.getInstance().returnBitMap(u.getThumb()));
        //android4.0后要访问网络资源需要单开线程，加入这段就不会报错了
        NetworkGlideImageLoader.getInstance().displayImage((Activity) context,commentFabulous.getHead(),head,0,0);
        NetworkGlideImageLoader.getInstance().displayImage((Activity) context,commentFabulous.getHead(),img,0,0);
        commentFabulousUserId.setText("" + commentFabulous.getUserId());
        commentFabulousCommentsId.setText("" + commentFabulous.getCommentsId());
        commentFabulousName.setText(commentFabulous.getName());
        commentFabulousId.setText("" + commentFabulous.getId());
        commentFabulousMessage.setText(commentFabulous.getMessage());
        commentFabulousTime.setText(commentFabulous.getTime());
        if(commentFabulous.getCf() != null){
            commentFabulousCf.setVisibility(convertView.VISIBLE);
        }else {
            commentFabulousCf.setVisibility(convertView.INVISIBLE);
        }
        return convertView;
    }


}



